package demon1;

public class Test {
    public static String longestCommonPrefix(String[] strs) {
        String str1 = strs[0];
        if(strs==null||strs.length==0){
            return "";
        }
        // List list=new LinkedList();
        for (int i = 1; i < strs.length; i++) {
            int m = 0;
            if (str1.charAt(0) != strs[i].charAt(0)) {
                break;
            }
            int j=0;
            for (j = 0; j < strs[i].length(); j++) {
                if (j<str1.length()&&str1.charAt(m) == strs[i].charAt(j)) {
                    // list.add(str1.charAt(m));
                    m++;
                }else{
                    break;
                }

            }
            str1=str1.substring(0,m);

        }
        return str1;
    }

    public static void main(String[] args) {
        String[] strs={"","","assd","assdf","assdfg","assb"};
        System.out.println(longestCommonPrefix(strs));
    }


}
